package hu.radai.jsfportal.taglib;

import hu.radai.jsfportal.log.LogManagerUtil;

import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.component.ValueHolder;
import javax.faces.webapp.UIComponentELTag;

public class MenuTag extends UIComponentELTag {

    private ValueExpression lang;
    private ValueExpression menu;
    
    public ValueExpression getLang() {
		return lang;
	}
    
    public void setLang(ValueExpression lang) {
        this.lang = lang;
    }

    public ValueExpression getMenu() {
		return menu;
	}
    
    public void setMenu(ValueExpression menu) {
        this.menu = menu;
    }

    public String getRendererType() {
        return ("menuTag");
    }

    public String getComponentType() {
        return ("menuTag");
    }
    
    public void release() {
    	super.release();
    	this.lang = null;
    	this.menu = null;
    }

    protected void setProperties(UIComponent component) {
        super.setProperties(component);
        
        UIMenu uiMenu = (UIMenu) component;

        if (lang != null) {
        	if (!lang.isLiteralText()) {
            	uiMenu.setValueExpression("lang", lang);
        	} else {
        		uiMenu.setLang(lang.getExpressionString());
        	}
        }
        
        if (menu != null) {
        	if (!menu.isLiteralText()) {
        		uiMenu.setValueExpression("menu", menu);
        	} else {
        		//uiMenu.setMenu(menu.getExpressionString());
        		LogManagerUtil.error(MenuTag.class, "not EL expression", new IllegalArgumentException("menu"));
        	}
        }
        /*
        if (uiMenu instanceof ValueHolder) {
            ValueHolder valueHolder = (ValueHolder) component;
            if (menu != null) {
                if (!menu.isLiteralText()) {
                	uiMenu.setValueExpression("menu", menu);
                } else {
                    valueHolder.setValue(menu.getExpressionString());
                }
            }
        }
        */
    }
}
